﻿using Microsoft.AspNetCore.Authorization;
using MiniFox.Platform.OAuth2.Web.Filters;
using MiniFox.Web.Filters;
using MiniFox.Web.Infrastructure;

namespace MiniFox.Platform.OAuth2.Web
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [AllowAnonymous, NoCache, PassportFilter, ValidationFilter]
    public abstract class OAuth2ControllerBase<T> : MvcControllerBase
    {
        #region 组件
        T _authService;
        /// <summary>
        /// 
        /// </summary>
        protected virtual T Component
        {
            get
            {
                if (_authService == null)
                {
                    _authService = this.Container.GetComponent<T>(this.CurrentStateManagement);
                }
                return _authService;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected IAuthenticationStateManagement CurrentStateManagement
        {
            get { return this.HttpContext.Items[AuthorizationStateManagement.AUTH_STATE_CONTEXT] as IAuthenticationStateManagement; }
        }
        #endregion
    }
}
